<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="produce_device" :rules="rules" label-width="100px" id="mvcfm">
      <el-button @click="devAddNewSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/mes/produce/CartogramProductionDevice?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
      <div class="form-unit">
        <span class="mvc-title-left"> 生产设备 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="分类" prop="menu_class">
              <el-radio-group v-model="produce_device.menu_class" onClick='javascript:updateFrom(this.value)'>
                <el-radio-button label="生产设备">生产设备</el-radio-button>
                <el-radio-button label="模具夹具">模具夹具</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="条形码" prop="produce_barcode">
              <el-input v-model="produce_device.produce_barcode" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产设备名称" prop="produce_name">
              <el-input v-model="produce_device.produce_name" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产设备型号" prop="produce_model">
              <el-input v-model="produce_device.produce_model" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产设备规格" prop="produce_norm">
              <el-input v-model="produce_device.produce_norm" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="供应商" prop="">
              {{produce_device.produce_maker}}
              <el-button @click="popSupplierSelect('','produce_maker')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
              <a href="/xcapi/MVCAction/myerp/supplychainmana/SupplierAdd.do?CMID5=13'+vueparams+'" class='btn btn-primary btn-minier'>增加供应商</a>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="制造商" prop="">
              {{produce_device.produce_supper}}
              <el-button @click="popSupplierSelect('','produce_supper')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工作能力(/S)" prop="produce_able">
              <el-input v-model="produce_device.produce_able" />
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <div class="form-unit">
        <span class="mvc-title-left"> 附加说明 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="简短描述" prop="produce_simdescribe">
              <el-input v-model="produce_device.produce_simdescribe" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="具体描述" prop="produce_describe">
              <el-input type="textarea" v-model="produce_device.produce_describe" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="devAddNewSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/mes/produce/CartogramProductionDevice?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
    </el-form>
    <el-dialog :visible.sync="SupplierSelectVisible" append-to-body>
      <SupplierSelect v-if="SupplierSelectVisible" ref="SupplierSelect" :popparams="popparams"> </SupplierSelect>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SupplierSelect from "@/views/mes/main/SupplierSelect";
  export default {
    name: 'DevAddNew',
    components: {
      SupplierSelect,
    },
    props: ['popparams'],
    data() {
      return {
        SupplierSelectVisible: false,
        SupplierSelectValue: null,
        SupplierSelectDesc: null,
        vueparams: this.getVUEParams(""),
        produce_device: {
          menu_class: null,
          produce_barcode: null,
          produce_name: null,
          produce_model: null,
          produce_norm: null,
          produce_maker: null,
          produce_supper: null,
          produce_able: null,
          produce_simdescribe: null,
          produce_describe: null,
        },
        loading: false,
        rules: {
          produce_name: [{
            required: true,
            message: "生产设备名称不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/produce/ProDeviceAction/devAddNew?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      devAddNewSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/produce/ProDeviceAction/devAddNewSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/produce/ProDeviceDet/proDeviceDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popSupplierSelect(desc, value) {
        this.SupplierSelectVisible = true;
        this.SupplierSelectDesc = desc;
        this.SupplierSelectValue = value;
      },
      closeSupplierSelect(value, desc) {
        this.SupplierSelectVisible = false;
        this.$set(this.produce_device, this.SupplierSelectDesc, desc);
        this.$set(this.produce_device, this.SupplierSelectValue, value);
      },
    },
  }
</script>
